package com.mihong.main;

import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.core.RedisTemplate;

import com.mihong.handler.ReplayHandler;
import com.mihong.util.HexUtil;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisTest {

	private Jedis jedis;//非切片额客户端连接
 
//    @Before
    public void initialPool() { 
        // 池基本配置 
        JedisPoolConfig config = new JedisPoolConfig(); 
        config.setMaxIdle(5); 
        config.setTestOnBorrow(false); 
        //获取连接
        jedis = new JedisPool(config,"127.0.0.1",6379).getResource(); 
    }
  
    @Test
    public void testString() {
    	String string= "123456";
    	StringBuilder sb = new StringBuilder();
    	for(int i=0,j=1;i<string.length()/2;i++,j++) {
    		if(2*(j+1) > string.length()) {
    			sb.append(string.substring(2*i, 2*j));
    		}else {
    			sb.append(string.substring(2*i, 2*j)+"-");
    		}
    	}
    	System.out.println(sb.toString());
    }

    @Test
	public void test(){
    	byte a = (byte)0xFF;
		System.out.println(a);
	}

    /**
     * 16进制转换测试
     */
    @Test
    public void testHex() {
    	byte[] arr = {(byte)0xFE,(byte)0xFE,0x10,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x12,0x00,0x09,0x00,0x20,0x19,0x08,0x00,
    			0x01,0x01,0x01,0x2C,0x37,(byte)0xBA,(byte)0xEE,(byte)0xEE};
    	for (byte b : arr) {
			System.out.print(b+" ");
		}
    	System.out.println("\n----------------------\n");
    	
    	byte[] str2HexStr = HexUtil.hexStringToBytes("FEFE100011223344556612000900201908000101012C37BAEEEE");
    	for (byte b : str2HexStr) {
			System.out.print(b+" ");
		}
    	System.out.println("\n----------------------\n");
    	String bytesToHexString = HexUtil.bytesToHexString(arr);
    	System.out.println(bytesToHexString);
    }
  
    
	
}
